﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using 晨曦超市管理系统.主页面;
using 晨曦超市管理系统.收款1;


namespace 晨曦超市管理系统
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }
        public static string NAME;
        public static string UserNameID;
        private void button1_Click(object sender, EventArgs e)
        {
            SqlDataReader rd = null;
            try
            {
                string sqlstr = string.Format("select * from informationOfEmployees where UserNameID='{0}' and Paw='{1}' ", idName.Text.Trim(), paw.Text.Trim());
                rd = DBHelper.DateReader(sqlstr);
                //判断我是否找了，没有找的就是flase
                if (!rd.Read())
                {
                    MessageBox.Show("用户账号错误和用户密码错误");

                }
                else
                {
                    MessageBox.Show("登录成功");
                    NAME = rd["Name"].ToString();
                    UserNameID = rd["UserNameID"].ToString();
                    //判断我的职位，呈现不同的界面
                    if (rd["Position"].ToString() == "管理员")
                    {
                        //如果上面的执行了，就可以关闭
                        if (rd != null)
                        {
                            rd.Close();
                        }
                    
                    Main_form Main1 = new Main_form();
                    Main1.Show();
                    this.Hide();
                    }
                    else
                    {
                        if (rd != null)
                        {
                            rd.Close();
                        }

                        ReceivablesForm ReceivablesForm = new ReceivablesForm();
                        ReceivablesForm.Show();
                        this.Hide();
                    }
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登录异常请尽快联系管理员原因"+ex.Message);
            }
            finally 
            {
                //如果上面的执行了，就可以关闭
                if (rd != null)
                {
                    rd.Close();
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Reusing.TuiChu();
        }
        private void Login_FormClosing(object sender, FormClosingEventArgs e)
        {
           
        }
        private void Login_Load(object sender, EventArgs e)
        {

        }

       
    }
}
